{include file="public/_meta" /}
<body>
<style>
    .required_b{
        color: red;
    }
</style>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">投放城市统计</h4>
<!--                                    <div class="layui-btn-container" style="margin-left: 65%">-->
<!--                                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>-->
<!--                                        <button type="button" class="layui-btn" id="test9">导入</button>-->
<!--                                    </div>-->
<!--                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">-->
<!--                                        <i class="fa fa-plus"></i>-->
<!--                                        添加-->
<!--                                    </button>-->

                                </div>

                                <form class="row">

<!--                                    <div class="col-md-6 col-lg-2">-->
<!--                                        <div class="form-group">-->

<!--                                            <select class="form-control input-full" name="gtype" id="gtype">-->
<!--                                                <option value="1"  {if condition="$groupType eq 1"}selected{/if}>账户维度统计</option>-->
<!--                                                <option value="2"  {if condition="$groupType eq 2"}selected{/if}>城市维度统计</option>-->
<!--&lt;!&ndash;                                                <option value="3"  {if condition="$groupType eq 3"}selected{/if}>商户维度统计</option>&ndash;&gt;-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->

                                    {if condition="$groupType eq 1"}

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="acc_name" value="{$acc_name}" placeholder="账户名称">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="adv_id" value="{$adv_id}" placeholder="账户ID">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="channel_id" id="channel_id">
                                                <option value="">渠道</option>
                                                {volist name="channels" id="vo"}
                                                <option value="{$key}">{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    {else /}
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="cityname" value="{$cityname}" placeholder="请输入城市">
                                        </div>
                                    </div>
                                    {/if}


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="pro_id" id="pro_id">
                                                <option value="">全部产品</option>
                                                {volist name="products" id="vo"}
                                                <option value="{$key}">{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="times" id="times" value="{$showTime}" placeholder="时间" autocomplete="off">
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <button type="button" class="btn btn-primary" onclick="dataexport()">导出</button>
                                            <a href="{:url('Operate/accountClueTotal')}" class="btn btn-info" style="color: white;position: absolute;left: 200px;">重置</a>
                                        </div>
                                    </div>

                                </form>

                            </div>

                            <div class="layui-card-body">

                                <blockquote class="layui-elem-quote layui-quote-nm">
<!--                                    <span style="margin-right: 50px;">账户消耗：{$nowXiaoHao}</span>-->
<!--                                    <span style="margin-right: 50px;">账户转化量：{$nowZhuanghua}</span>-->
<!--                                    <span style="margin-right: 50px;">账户成本：{$nowChengBen}</span>-->
<!--                                    <span style="margin-right: 50px;">API进线消耗：{$apiJinXianXiaohao}</span>-->
<!--                                    <span style="margin-right: 50px;">API进线量：{$apiJixXianNum}</span>-->
<!--                                    <span style="margin-right: 50px;">进线损耗率：{$jinXianShunHaoRate}%</span>-->
<!--                                    <span style="margin-right: 50px;">真实成本：{$apiJinXianChengBen}</span>-->
<!--                                    <span style="margin-right: 50px;">分发成功量：{$nowFenfaNum}</span>-->
<!--                                    <span style="margin-right: 50px;">分发损耗率：{$fenFaShunHaoRare}%</span>-->
<!--                                    <span style="margin-right: 50px;">总损耗率：{$allShunHaoRare}%</span><br>-->
<!--                                    <span style="margin-right: 50px;">重复量：{$reClueNum}</span>-->
<!--                                    <span style="margin-right: 50px;">重复率：{$reClueRate}%</span>-->
<!--                                    <span style="margin-right: 50px;">非目标城市：{$reCity}</span>-->
<!--                                    <span style="margin-right: 50px;">非目标城市率：{$reCityRate}%</span>-->
<!--                                    <span style="margin-right: 50px;">撞库量：{$rePhone}</span>-->
<!--                                    <span style="margin-right: 50px;">撞库率：{$rePhoneRate}%</span>-->
<!--                                    <span style="margin-right: 50px;">分发总金额：{$pushMoney}</span>-->
<!--                                    <span style="margin-right: 50px;">分发客单：{$pushAvgMoney}</span>-->
<!--                                    <span style="margin-right: 50px;">收发总差额：{$nowShouFaAllCha}</span>-->
<!--                                    <span style="margin-right: 50px;">收发客单差额：{$nowKeDanCha}</span>-->


                                    <div class="table-responsive">
                                        <table id="add-row2" class="display table table-striped table-hover" >
                                            <thead>
                                            <tr>
                                                <th>本页统计</th>
                                                <th>账户消耗</th>
                                                <th>账户转化量</th>
                                                <th>账户成本</th>
                                                <th>API进线消耗</th>
                                                <th>API进线量</th>
                                                <th>进线损耗率</th>
                                                <th>真实成本</th>
                                                <th>分发成功量</th>
                                                <th>分发损耗率</th>
                                                <th>总损耗率</th>
                                                <th>重复量</th>
                                                <th>重复率</th>
                                                <th>非目标城市</th>
                                                <th>非目标城市率</th>
                                                <th>撞库量</th>
                                                <th>撞库率</th>
                                                <th>分发总金额</th>
                                                <th>分发客单</th>
                                                <th>收发总差额</th>
                                                <th>收发客单差额</th>
                                            </tr>
                                            </thead>

                                            <tbody>

                                            <tr>
                                                <td>第{$infos->currentPage()}页</td>
                                                <td>{$nowXiaoHao}</td>
                                                <td>{$nowZhuanghua}</td>
                                                <td>{$nowChengBen}</td>
                                                <td>{$apiJinXianXiaohao}</td>
                                                <td>{$apiJixXianNum}</td>
                                                <td>{$jinXianShunHaoRate}%</td>
                                                <td>{$apiJinXianChengBen}</td>
                                                <td>{$nowFenfaNum}</td>
                                                <td>{$fenFaShunHaoRare}%</td>
                                                <td>{$allShunHaoRare}%</td>
                                                <td>{$reClueNum}</td>
                                                <td>{$reClueRate}%</td>
                                                <td>{$reCity}</td>
                                                <td>{$reCityRate}%</td>
                                                <td>{$rePhone}</td>
                                                <td>{$rePhoneRate}%</td>
                                                <td>{$pushMoney}</td>
                                                <td>{$pushAvgMoney}</td>
                                                <td>{$nowShouFaAllCha}</td>
                                                <td>{$nowKeDanCha}</td>
                                            </tr>

                                            </tbody>
                                        </table>


                                    </div>


                                </blockquote>
                            </div>


                            <div class="card-body">
                                <!-- Modal -->


                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            {if condition="$groupType eq 1"}
                                            <th>渠道</th>
                                            <th>账户信息</th>
                                            {else /}
                                            <th>城市</th>
                                            {/if}
                                            <th>产品</th>

                                            <th>账户消耗</th>
                                            <th>账户转化量</th>
                                            <th>账户成本</th>
                                            <th>API进线消耗</th>
                                            <th>API进线量</th>
                                            <th>进线损耗率</th>
                                            <th>真实成本</th>
                                            <th>分发成功量</th>
                                            <th>分发损耗率</th>
                                            <th>总损耗率</th>
                                            <th>重复量</th>
                                            <th>重复率</th>
                                            <th>非目标城市</th>
                                            <th>非目标城市率</th>
                                            <th>撞库量</th>
                                            <th>撞库率</th>
                                            <th>分发总金额</th>
                                            <th>分发客单</th>
                                            <th>收发总差额</th>
                                            <th>收发客单差额</th>
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>
                                            {if condition="$groupType eq 1"}
                                            <td>{$vo.channel_name}</td>
                                            <td>
                                                账户ID：{$vo.adv_id}<br>
                                                名称：{$vo.acc_name}<br>
                                                简称：{$vo.acc_desc}
                                            </td>
                                            {else /}
                                            <td>{$vo.city_name}</td>
                                            {/if}
                                            <td>{$vo.pro_name}</td>
                                            <td>{$vo.e_money}</td>
                                            <td>{$vo.e_zhuanhua}</td>
                                            <td>{$vo.e_chengben}</td>
                                            <td>{$vo.e_true_consume}</td>
                                            <td>{$vo.clue_num}</td>
                                            <td>{$vo.jinxiansunhao_rate}%</td>
                                            <td>{$vo.avg_api_clue}</td>
                                            <td>{$vo.push_num}</td>
                                            <td>{$vo.push_rate}%</td>
                                            <td>{$vo.all_push_rate}%</td>
                                            <td>{$vo.re_clue_num}</td>
                                            <td>{$vo.re_clue_rate}%</td>
                                            <td>{$vo.re_clue_city}</td>
                                            <td>{$vo.re_city_rate}%</td>
                                            <td>{$vo.re_phone}</td>
                                            <td>{$vo.re_phone_rate}%</td>
                                            <td>{$vo.price}</td>
                                            <td>{$vo.push_avg_money}</td>
                                            <td>{$vo.e_sf_all_cha}</td>
                                            <td>{$vo.e_sf_avg_sub}</td>
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('clue/status')}",
        'delete_url':"{:url('clue/delete')}",
        'item_url':"{:url('clue/edit')}",
        'item_url2':"{:url('clue/edit2')}",
        'add_url':"{:url('clue/save')}",
        'clue_url':"{:url('clue/clue_url')}",
        'city_url':"{:url('clue/getRegion')}",
        'push_rule':"{:url('clue/getMerchantPush')}",
        'push_url':"{:url('clue/findPush')}",
        'get_account':"{:url('stat/getAccount')}",
        'saveclue':"{:url('stat/saveClueCost')}",
        'editclue':"{:url('stat/editClueCost')}",
        'del_clue':"{:url('stat/delClueCost')}",
        'improtexcel':"{:url('stat/importClueCost')}",
    };


    function loadRule(sel,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.get_account,{pid:$("#"+sel).val()},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.acc_name+"】【账号ID"+v.adv_id+"】</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    function loadRegion(sel,type_id,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.city_url,{pid:$("#"+sel).val(),type:type_id},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(idx,item){
                        $("<option value="+item.id+">"+item.name+"</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{
                clue_name:{
                    required:true,
                    maxlength:30
                },
                phone:{
                    required:true,
                    number:true,
                    minlength:11,
                    maxlength:11
                },
                age:{
                    number:true
                },
                email:{
                    email:true,
                    maxlength:100
                },
                wx_id:{
                    maxlength:30
                },
                qq:{
                    maxlength:30
                },
                remark:{
                    maxlength:300
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.saveclue;
                if(commitStatus==true){
                    return false;
                }
                var province = $("#province").val();
                var city = $("#city").val();
                if(province != 0 && city == 0){
                    layer.msg('请选择市/县',{icon:2,time:2000});
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal2").validate({

            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.push_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        $("input[name='id']").val(id);
        document.getElementById('form-modal').reset();
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $(".fw-mediumbold").text('添加');
    }

    function edit_item(id) {
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $.ajax({
            type: 'GET',
            url: SCOPE.editclue,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('编辑');
                    $("#id").val(res.data.id);

                    $("#channel").find("option[value="+res.data.channel_id+"]").attr("selected",true);
                    $("#account").children().remove();
                    $("<option value='"+res.data.acc_id+"'>【"+res.data.acc_name+"】【账号ID"+res.data.adv_id+"】</option>").appendTo($("#account"));
                    $("#dtime").val(res.data.time);
                    $("#exposure_val").val(res.data.exposure_val);
                    $("#click_val").val(res.data.click_val);
                    $("#money").val(res.data.money);
                    $("#transform_val").val(res.data.transform_val);
                    $("#clue_num").val(res.data.clue_num);
                    $("#change_cost").val(res.data.change_cost);
                    $("#true_cost").val(res.data.true_cost);
                    $("#remark").val(res.data.remark);
                    $("#province").val(res.data.prov);
                    if(res.data.city != ''){
                        $("#city").children().remove();
                        $("<option value='"+res.data.city+"'>"+res.data.city_name+"</option>").appendTo($("#city"));
                    }
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    function edit_item2(id,city) {
        $("#mrule").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#mrule"));
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url2,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('推送');
                    $("#id2").val(res.data.id);
                    $("#clue_name2").val(res.data.clue_name);
                    $("#phone2").val(res.data.phone);

                    $("#remark2").val(res.data.remark);
                    $("#city2").text(city);

                    $("#merchant").children().remove();


                    $.each(res.data.merchant,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.mer_name+"】【账号"+v.username+"】(联系电话"+v.phone+")</option>").appendTo($("#merchant"));
                    });

                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }



    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.del_clue,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除线索成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }



    laydate.render({
        elem: '#times'
        ,type: 'date'
        ,range: true
    });

    //自定义格式
    laydate.render({
        elem: '#dtime'
        ,format: 'yyyy-MM-dd'
    });

    // $('#channel_id').find('option[value="{$channel_id}"]').attr('selected',true);
    // $('#pro_id').find('option[value="{$pro_id}"]').attr('selected',true);

    $('#channel_id').val('{$channel_id}');
    $('#pro_id').val('{$pro_id}');



    function dataexport(){
        var cityname=$("[name='cityname']").val();
        var pro_id=$("[name='pro_id']").val();
        var times=$("[name='times']").val();
        location.href="{:url('Operate/accountClueTotalExprot')}"+'?cityname='+cityname+'&pro_id='+pro_id+'&times='+times;
    }

</script>
<script src="__STATIC__/layui/layui.js"></script>
<script>
    layui.use(['upload', 'element', 'layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;

        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: "{:url('stat/importClueCost')}" //此处配置你自己的上传接口即可
            ,auto: false
            //,multiple: true
            ,accept:'file'
            ,bindAction: '#test9'
            ,done: function(res){
                if(res.code == 1001){
                    layer.msg(res.msg,{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon: 2,time:3000});
                }
            }
        });
    });
</script>
</html>




























